#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>

struct TreeNode {
	int val;
	struct TreeNode *left;
	struct TreeNode *right;
};
int TreeSize(struct TreeNode* root)
{
	return root == NULL ? 0 : TreeSize(root->left) + TreeSize(root->right) + 1;
}

void preorder(struct TreeNode* root, int* arr, int* pi)
{
	if (root == NULL)
		return;
	arr[(*pi)++] = root->val;
	preorder(root->left, arr, pi);
	preorder(root->right, arr, pi);
}

int* preorderTraversal(struct TreeNode* root, int* returnSize)
{
	*returnSize = TreeSize(root);
	int* a = (int*)malloc(sizeof(int)*(*returnSize));
	int i = 0;
	preorder(root, a, &i);
	return a;
}

int main()
{
	
	
	return 0;
}